package org.mv.mm.api;

import org.mv.mm.api.data.IDataProvider;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.modules.ModuleInstall;
import org.openide.util.Lookup;

public class Installer extends ModuleInstall {

  @Override
  public void restored() {
    // TODO ?
  }

  @Override
  public boolean closing() {
    IDataProvider dataProvider = Lookup.getDefault().lookup(IDataProvider.class);

    if ( !dataProvider.persistData(true) ) {
      NotifyDescriptor d = new NotifyDescriptor.Confirmation(
              "The data has NOT been saved! Do you wish to exit the application anyway?",
              "Saving failed",
              NotifyDescriptor.YES_NO_OPTION);
      if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.YES_OPTION) {
        return super.closing();
      } else {
        return false;
      }
    }
    return super.closing();
  }
}
